﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace vnFingerPrint.SDK.Library
{
    public class Helper
    {
        public static float[] InputANN(string CoreDelta,string dacTrung)
        {
            float[] cores = new float[6];
            string[] cs = CoreDelta.Split(';');
            for(int i=0;i<6;i++)
            {
                cores[i] = float.Parse(cs[i]);
            }
            float[] results = new float[16];
            results[0] = cores[2]; results[1] = cores[3]; results[2] = cores[4]; results[3] = cores[5];
            List<PointF> p1 = new List<PointF>(), p2 = new List<PointF>(), p3=new List<PointF>(), p4=new List<PointF>();
            cs = dacTrung.Split(';');
            for(int i=7;i<cs.Length-6;i+=6)
            {
                float x = float.Parse(cs[i]);
                float y = float.Parse(cs[i + 1]);
                if(x!=0||y!=0)
                {
                    if (x >=0 && y >= 0)
                        p1.Add(new PointF(x, y));
                    else if (x >=0 && y < 0)
                        p2.Add(new PointF(x,y));
                    else if(x<0&&y<0)
                        p3.Add(new PointF(x, y));
                    else if (x < 0 && y >= 0)
                        p4.Add(new PointF(x, y));
                }
            }
            PointF p = TrungBinh(p1);
            results[4] = p.X; results[5] = p.Y; results[6] = p1.Count;
            p = TrungBinh(p2);
            results[7] = p.X; results[8] = p.Y; results[9] = p2.Count;
            p = TrungBinh(p3);
            results[10] = p.X; results[11] = p.Y; results[12] = p3.Count;
            p = TrungBinh(p4);
            results[13] = p.X; results[14] = p.Y; results[15] = p4.Count;
            return results;
        }
        private static PointF TrungBinh(List<PointF> p)
        {
            if (p.Count == 0)
                return new PointF(0,0);
            PointF re = new PointF(0,0);
            foreach(PointF j in p)
            {
                re.X += j.X; re.Y += j.Y;
            }
            re.X = re.X / p.Count;
            re.Y = re.Y / p.Count;
            return re;
        }
    }
}
